package com.dream21th.generate.controller;

import com.dream21th.common.ComReq;
import com.dream21th.common.ComResp;
import com.dream21th.generate.biz.GenerateBiz;
import com.dream21th.generate.dto.MysqlDTO;
import com.dream21th.generate.dto.TableDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;

@RestController
public class GenerateController {

    @Autowired
    private GenerateBiz generateBiz;

    @PostMapping("/generateCode")
    public ComResp<String> generateCode(@RequestBody ComReq<MysqlDTO> dto){
        return new ComResp<String>().data(generateBiz.generateCode(dto.getRequestData())).success();
    }

    @PostMapping("/obtainlDataBases")
    public ComResp<List<String>> obtainlDataBases(@RequestBody ComReq<MysqlDTO> dto){
        return new ComResp<List<String>>().data(generateBiz.obtainlDataBases(dto.getRequestData())).success();
    }

    @PostMapping("/obtainTables")
    public ComResp<List<TableDTO>> obtainTables(@RequestBody ComReq<MysqlDTO> dto){
        return new ComResp<List<TableDTO>>().data(generateBiz.obtainTables(dto.getRequestData())).success();
    }
}
